package com.suket.jnn;

import java.util.Iterator;
import java.util.List;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;

public class LayerSupport {

  static Logger logger = Logger.getLogger(LayerSupport.class);

  public static int getTotalNodes( Layer layer ) {
    int totalNodes = 0;
    if ( layer == null ) {
      logger.log(Level.WARN, "Failed to get total nodes , found null layer");
      return totalNodes;
    }
    List listNodes = layer.getNodes();
    if ( listNodes == null ) {
      logger.log(Level.WARN, "Failed to get total nodes , found null nodes");
      return totalNodes;
    }
    totalNodes = listNodes.size();
    return totalNodes;
  }

  public static void info( Layer layer ) {
    if ( layer == null ) {
      logger.log(Level.WARN, "Failed to perform info , found null layer");
      return;
    }
  }

  public static String infoWeights( Layer layer , int tab ) {
    String result = "";
    if ( layer == null ) {
      logger.log(Level.WARN, "Failed to perform info weights "
          + ", found null layer");
      return result;
    }
    List listNodes = layer.getNodes();
    if ( listNodes == null ) {
      return result;
    }
    int idx = 0;
    Iterator iterNodes = listNodes.iterator();
    while ( iterNodes.hasNext() ) {
      Node node = (Node) iterNodes.next();
      String infoNodeWeights = NodeSupport.infoWeights(node);
      result += CommonUtil.tab(tab) + "n[" + ( idx++ ) + "]: { "
          + infoNodeWeights + " } \n";
    }
    return result;
  }

}
